(function () {
    var __bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; };
    window.Map = (function () {
        Map.prototype.xoffset = 427.8;
        Map.prototype.xfactor = 2.329899;
        Map.prototype.yoffset = 272.6659;
        Map.prototype.yfactor = -2.6999;
        function Map(opts) {
            if (opts == null) {
                opts = {};
            }
            this.locationLinks = j$('#location-links');
            this.breadcrumbs = j$('#map-breadcrumbs');
            this.legend = j$('#map-legend');
            this.secondBreadcrumbLink = this.breadcrumbs.find('.second');
            this.activeRegion = null;
            this.lastPinClicked = null;
            this.regions = {};
            this.points = [];
            this.currentlyAnimating = false;
            this.dialogOpen = false;
            this.afterInit = opts.afterInit || function () { };

            // zoom in / out animation speed
            this.zoomSpeed = opts['zoomSpeed'] || 1000;
            this.language = opts['language'] || 'en';
            this.locationsBulletClub = opts['locationsBulletClub'] || 'locationsBulletClub';
            this.aPartnerHotel = opts['aPartnerHotel'] || 'aPartnerHotel';
            this.futureOpenings = opts['futureOpenings'] || '';
            this.aRitzReserve = opts['aRitzReserve'] || 'aRitzReserve';

            //console.log("language = " + this.language);

            this.elem = j$('#map');
            this.addRegions();

            // wait for main map to load before completing init
            this.img = j$('#world-map').load(__bind(function () {
                this.bindListToggle();
                this.width = this.img.css('width');
                this.widthNum = Number(this.width.replace('px', ''));
                this.height = this.img.css('height');
                this.heightNum = Number(this.height.replace('px', ''));
                this.varnish = this.elem.find('#transparent-map');
                this.zoomOutLink = j$('#zoom-out-link');
                this.bindZoomOut();
                this.addPoints();
                this.drawPoints();
                this.dialog = new Dialog(this);
                return this.afterInit();
            }, this));
            
            this.img.each(function() {
				if (this.complete) {
					j$(this).trigger('load');
				}
			});
            // kick off the above load handler
            //this.img.attr('src', '/images2011/maps/world_full.png');
            this.img.attr('src', mapBaseImg);
        };

        Map.prototype.adjustPoints = function () {
            setInterval((__bind(function () {
                return this.drawPoints();
            }, this)), 300);
            return j$(document).keypress(__bind(function (e) {
                var active;
                active = this.activeRegion ? this.activeRegion : this;
                switch (e.which) {
                    case 97:
                        active.xfactor -= 0.01;
                        break;
                    case 100:
                        active.xfactor += 0.01;
                        break;
                    case 119:
                        active.yfactor -= 0.01;
                        break;
                    case 115:
                        active.yfactor += 0.01;
                        break;
                    case 105:
                        active.yoffset -= 0.3;
                        break;
                    case 107:
                        active.yoffset += 0.3;
                        break;
                    case 106:
                        active.xoffset -= 0.3;
                        break;
                    case 108:
                        active.xoffset += 0.3;
                }
                //console.log("xoffset = " + active.xoffset);
                //console.log("xfactor = " + active.xfactor);
                //console.log("yoffset = " + active.yoffset);
                return console.log("yfactor = " + active.yfactor);
            }, this));
        };

        Map.prototype.bindListToggle = function () {
            var bclis, mc, mt, viewList, viewMap;
            this.locationLinks.hide();
            this.breadcrumbs.show();
            this.legend.show();
            bclis = this.breadcrumbs.find('li');
            mt = j$('#map-toggle').show();
            mc = j$('#map-container').show();
            viewList = mt.find('#view-list-toggle');
            viewMap = mt.find('#view-map-toggle');
            viewList.bind('click', __bind(function () {
                viewList.addClass('active');
                viewMap.removeClass('active');
                mc.hide();
                bclis.fadeOut();
                this.legend.hide();
                return this.locationLinks.fadeIn();
            }, this));
            return viewMap.bind('click', __bind(function () {
                viewList.removeClass('active');
                viewMap.addClass('active');
                this.locationLinks.hide();
                this.legend.show();
                bclis.fadeIn();
                return mc.fadeIn();
            }, this));
        };
        Map.prototype.bindZoomOut = function () {
            this.zoomOutLink.bind('click', __bind(function () {
                return this.zoomOut();
            }, this));

            // escape key behavior
            return j$(document).keydown(__bind(function (e) {
                if (e.keyCode === 27) {
                    if (this.lastPinClicked) {
                        this.lastPinClicked.img.qtip('hide');
                    }
                    if (this.currentlyAnimating || !this.activeRegion) {
                        return;
                    }
                    this.zoomOut();
                    return this.blurPoints();
                }
            }, this));
        };
        Map.prototype.zoomOut = function () {
            var zd;
            if (!((this.activeRegion != null) && this.zoomOutLink.is(':visible'))) {
                return;
            }
            this.currentlyAnimating = true;
            this.zoomOutLink.hide();
            this.hidePoints();
            zd = this.activeRegion.zoomable.dimensions;
            return this.activeRegion.zoomable.animate({
                width: zd.width,
                height: zd.height,
                top: zd.top,
                left: zd.left
            }, this.zoomSpeed, __bind(function () {
                this.secondBreadcrumbLink.removeClass('active');
                this.varnish.attr('usemap', '#region-map-view');
                this.activeRegion.zoomable.hide();
                this.activeRegion.hover.fadeOut('fast', __bind(function () {
                    this.currentlyAnimating = false;
                    return this.blurRegions();
                }, this));
                this.activeRegion = null;
                return this.drawPoints();
            }, this));
        };

        // pull region data from the dom
        Map.prototype.addRegions = function () {
            var region, _i, _len, _ref, _results;
            _ref = this.elem.find('area');
            _results = [];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                region = _ref[_i];
                _results.push(new Region(this, region));
            }
            return _results;
        };
        Map.prototype.addPoints = function () {
            var point, _i, _len, _ref, _results;
            _ref = this.locationLinks.find('a');
            _results = [];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                point = _ref[_i];
                _results.push(new Point(this, point));
            }
            return _results;
        };
        Map.prototype.drawPoints = function () {
            var point, _i, _len, _ref, _results;
            _ref = this.points;
            _results = [];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                point = _ref[_i];
                _results.push(point.draw());
            }
            return _results;
        };
        Map.prototype.hidePoints = function () {
            var point, _i, _len, _ref, _results;
            _ref = this.points;
            _results = [];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                point = _ref[_i];
                _results.push(point.hide());
            }
            return _results;
        };
        Map.prototype.blurPoints = function () {
            var point, _i, _len, _ref, _results;
            _ref = this.points;
            _results = [];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                point = _ref[_i];
                _results.push(point.blur());
            }
            return _results;
        };
        Map.prototype.blurRegions = function () {
            var name, region, _ref, _results;
            _ref = this.regions;
            _results = [];
            for (name in _ref) {
                region = _ref[name];
                _results.push(region.hide());
            }
            return _results;
        };
        return Map;
    })();
}).call(this);
